﻿Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Data.SqlClient
Imports System.Text
Imports System.Data
Namespace OAMS.DAO
    Public Class BaseDAO
        '''' <summary>
        '''' 取得AUO的資料庫
        '''' </summary>
        '''' <returns></returns>
        '''' <remarks></remarks>
        'Public Function MyConn() As SqlConnection
        '    Dim dbName As String = DBSetting.GetDBName("", "", "")
        '    Dim myConn__1 As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings(dbName).ConnectionString)
        '    Return myConn__1
        'End Function

        ''' <summary>
        ''' 取得AUO的資料庫
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Function MyConn(ByVal Param1 As String) As SqlConnection
            If String.IsNullOrEmpty(Param1) Then
                Param1 = System.Configuration.ConfigurationManager.AppSettings("DefaultDB")
            End If
            Dim dbName As String = DBSetting.GetDBName(Param1, "", "")
            Dim myConn__1 As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings(dbName).ConnectionString)
            Return myConn__1
        End Function

      
        Public Sub ErrorLog(ByVal Param1 As String, ByVal ProgamName As String, ByVal ErrMsg As String, ByVal FunctionName As String, ByVal byWho As String, ByVal ErrStatus As String)

            Dim sqlParams As SqlParameter() = New SqlParameter(4) {}

            sqlParams(0) = New SqlParameter("@ProgamName", SqlDbType.NVarChar, ProgamName.Length)
            sqlParams(0).Value = ProgamName
            sqlParams(1) = New SqlParameter("@ErrMsg", SqlDbType.NVarChar, ErrMsg.Length)
            sqlParams(1).Value = ErrMsg
            sqlParams(2) = New SqlParameter("@FunctionName", SqlDbType.NVarChar, FunctionName.Length)
            sqlParams(2).Value = FunctionName
            sqlParams(3) = New SqlParameter("@byWho", SqlDbType.NVarChar, byWho.Length)
            sqlParams(3).Value = byWho
            sqlParams(4) = New SqlParameter("@ErrStatus", SqlDbType.NVarChar, ErrStatus.Length)
            sqlParams(4).Value = ErrStatus

            Dim sb As New StringBuilder()

            sb.AppendLine(" insert into  ACMSErrorLog (Program ,ErrMsg ,FunctionName ,ByWho ,ErrStatus ) values(@ProgamName,@ErrMsg,@FunctionName,@byWho,@ErrStatus) ")


            SqlHelper.ExecuteNonQuery(MyConn(Param1), CommandType.Text, sb.ToString(), sqlParams)


        End Sub

    End Class

End Namespace





Namespace ACMS.DAO
    Public Class BaseDAO
        Public Function MyConn() As SqlConnection
            Dim myConn__1 As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("WFDB").ConnectionString)

            Return myConn__1


        End Function
        Public Sub ErrorLog(ByVal ProgamName As String, ByVal ErrMsg As String, ByVal FunctionName As String, ByVal byWho As String, ByVal ErrStatus As String)

            Dim sqlParams As SqlParameter() = New SqlParameter(4) {}

            sqlParams(0) = New SqlParameter("@ProgamName", SqlDbType.NVarChar, ProgamName.Length)
            sqlParams(0).Value = ProgamName
            sqlParams(1) = New SqlParameter("@ErrMsg", SqlDbType.NVarChar, ErrMsg.Length)
            sqlParams(1).Value = ErrMsg
            sqlParams(2) = New SqlParameter("@FunctionName", SqlDbType.NVarChar, FunctionName.Length)
            sqlParams(2).Value = FunctionName
            sqlParams(3) = New SqlParameter("@byWho", SqlDbType.NVarChar, byWho.Length)
            sqlParams(3).Value = byWho
            sqlParams(4) = New SqlParameter("@ErrStatus", SqlDbType.NVarChar, ErrStatus.Length)
            sqlParams(4).Value = ErrStatus

            Dim sb As New StringBuilder()

            sb.AppendLine(" insert into  ACMSErrorLog (Program ,ErrMsg ,FunctionName ,ByWho ,ErrStatus ) values(@ProgamName,@ErrMsg,@FunctionName,@byWho,@ErrStatus) ")


            SqlHelper.ExecuteNonQuery(MyConn(), CommandType.Text, sb.ToString(), sqlParams)


        End Sub



    End Class
End Namespace